package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author：gbc
 * @Project：sky-take-out
 * @Date：2025/9/24 16:08
 */
@Mapper
public interface CategoryMapper {
    /**
     * 分类查询
     *
     * @param categoryPageQueryDTO@return
     */
    Page<Category> page(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 分类新增
     * @param category
     */
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user) VALUES " +
            "(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void saveCategory(Category category);

    /**
     * 启用禁用分类
     * @param category
     */
    void update(Category category);

    /**
     * 根据分类id查询菜品或套餐
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> getDishByCategoryId(Long categoryId);

    /**
     * 根据分类id查询菜品个数
     * @param categoryId
     * @return
     */
    @Select("select count(*) from dish where category_id = #{categoryId} and status=1")
    Integer countByDish(Long categoryId);

    /**
     * 根据分类id查询套餐个数
     * @param categoryId
     * @return
     */
    @Select("select count(*) from setmeal where category_id=#{categoryId} and status=1")
    Integer countBySetmeal(Long categoryId);

    /**
     * 根据id删除分类
     * @param id
     */
    @Delete("delete from category  where id=#{id}")
    void delete(Long id);

    /**
     * 根据分类id查询分类
     * @param type
     * @return
     */
    @Select("select * from  category where type=#{type}")
    List<Category> getCategoryByType(Integer type);
}
